﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Converters="clr-namespace:GraphLight.Converters"
		xmlns:Controls="clr-namespace:GraphLight.Controls" xmlns:Drawing="clr-namespace:GraphLight.Drawing">

	<!-- Common resources -->
	<Converters:PointsToPolyLineConverter x:Key="polyLineConverter" />
	<ItemsPanelTemplate x:Key="canvasPanelTemplate">
		<Canvas />
	</ItemsPanelTemplate>

	<!-- Control point -->
	<Controls:ContainerBindingCollection x:Key="controlPointContainerBindings">
		<Controls:ContainerBinding Property="Canvas.Left" Binding="{Binding X, Mode=TwoWay}" />
		<Controls:ContainerBinding Property="Canvas.Top" Binding="{Binding Y, Mode=TwoWay}" />
	</Controls:ContainerBindingCollection>
	<DataTemplate x:Key="controlPointTemplate">
		<Ellipse Width="8" Height="8" Margin="-4,-4,0,0" Fill="White" Stroke="Red" StrokeThickness="1"
				Controls:ContainerBindings.BindingCollection="{StaticResource controlPointContainerBindings}" />
	</DataTemplate>
	<Style x:Key="controlPointContainerStyle" TargetType="ContentPresenter">
		<Setter Property="Controls:DragDropManager.AllowDrag" Value="True" />
	</Style>

	<!-- Graph -->
	<ControlTemplate x:Key="diagramTemplate" TargetType="Drawing:GraphControl">
		<Grid Background="Transparent" x:Name="LayoutRoot">
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="Auto" />
				<ColumnDefinition Width="*" />
			</Grid.ColumnDefinitions>
			<ListBox ItemsSource="{Binding EditorTools}" SelectedItem="{Binding SelectedEditorTool, Mode=TwoWay}">
				<ListBox.ItemTemplate>
					<DataTemplate>
						<TextBlock Text="{Binding Name}" Margin="5" FontSize="15" FontWeight="Bold" />
					</DataTemplate>
				</ListBox.ItemTemplate>
			</ListBox>
			<ScrollViewer x:Name="scrollViewer" Grid.Column="1" HorizontalScrollBarVisibility="Auto"
					VerticalScrollBarVisibility="Auto" Background="{x:Null}">
				<Grid x:Name="mainGrid" ShowGridLines="True" Background="Transparent"
						Controls:DragDropManager.AllowDrop="true">
					<Path x:Name="line" Stroke="Gray" StrokeThickness="0.5" StrokeDashArray="4,8"
							Data="{Binding SelectedEdge.Data.Points, Converter={StaticResource polyLineConverter}}"
							Height="{Binding Graph.Height}" Width="{Binding Graph.Width}" />
					<Canvas x:Name="graphCanvas" Height="{Binding Graph.Height}" Width="{Binding Graph.Width}" />
					<Controls:ItemsControlEx x:Name="controlPoints" HorizontalContentAlignment="Stretch"
							ItemsSource="{Binding SelectedEdge.Data.DraggablePoints}"
							ItemsPanel="{StaticResource canvasPanelTemplate}"
							ItemTemplate="{StaticResource controlPointTemplate}"
							ItemContainerStyle="{StaticResource controlPointContainerStyle}"
							Height="{Binding Graph.Height}" Width="{Binding Graph.Width}" />
				</Grid>
			</ScrollViewer>
		</Grid>
	</ControlTemplate>

	<Style TargetType="Drawing:GraphControl">
		<Setter Property="Template" Value="{StaticResource diagramTemplate}" />
	</Style>

</ResourceDictionary>